package com.kate.cloud.shiro.web;

import com.kate.cloud.shiro.util.ResultVOUtil;
import com.kate.cloud.shiro.vo.ResultVO;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 李金照 on 2017/12/13.
 *
 * @author 金照
 */
@ControllerAdvice
public class WebControllerAdvice {
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResultVO<String> errorHandler(Exception ex) {
        if(UnauthorizedException.class.isInstance(ex)){
            return ResultVOUtil.error("未授权");
        }
        return ResultVOUtil.error("异常");
    }
}
